package com.chuangsi.project.admin.controller.app;


import com.chuangsi.framework.web.controller.BaseController;
import com.chuangsi.framework.web.domain.ResultObject;
import com.chuangsi.project.admin.dto.app.order.*;
import com.chuangsi.project.admin.dto.app.payorder.OfflinePayOrderDto;
import com.chuangsi.project.admin.dto.app.payorder.OnlinePayOrderDto;
import com.chuangsi.project.admin.dto.app.payorder.PayOrderIdDto;
import com.chuangsi.project.admin.service.IPayOrderService;
import com.chuangsi.project.admin.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author 
 * @since 2024-05-10
 */
@Api(tags="APP-订单")
@RestController
@RequestMapping("/userApi/order/app")
public class AppOrderController extends BaseController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private IPayOrderService payOrderService;

    @ApiOperation(value = "获取是否支付成功", notes = "ywb")
    @GetMapping("/getPayStatus")
    public ResultObject<ResPlaceAnOrderDto> getPayStatus(@Validated PayOrderIdDto req) {
        Integer status = payOrderService.getPayStatus(req.getPayOrderId());
        return ResultObject.ok().setData(status);
    }

    @ApiOperation(value = "下支付订单", notes = "ywb")
    @PostMapping("/placeAnOrder")
    public ResultObject<ResPlaceAnOrderDto> placeAnOrder(@RequestBody @Validated ReqPlaceAnOrderDto req) {
        ResPlaceAnOrderDto data = orderService.placeAnOrder(req);
        return ResultObject.ok("下单成功").setData(data);
    }

    @ApiOperation(value = "获取支付成功但是未生产合同的订单", notes = "ywb")
    @GetMapping("/getNotFinishPayOrder")
    public ResultObject<List<ResPayOrderNotFinishDto>> getNotFinishPayOrder() {
        List<ResPayOrderNotFinishDto> data = payOrderService.getNotFinishPayOrder();
        return ResultObject.ok().setData(data);
    }

    @ApiOperation(value = "线下订单完成支付", notes = "ywb")
    @PostMapping("/offlinePay")
    public ResultObject<Void> offlinePay(@RequestBody @Validated OfflinePayOrderDto payOrderDto) {
        payOrderService.offlinePay(payOrderDto);
        return ResultObject.ok("支付成功");
    }

    @ApiOperation(value = "线上订单拉起支付", notes = "ywb")
    @PostMapping("/onlinePay")
    public ResultObject<ResPlaceAnOrderDto> onlinePay(@RequestBody @Validated OnlinePayOrderDto payOrderDto) {
        ResPlaceAnOrderDto resPlaceAnOrderDto = payOrderService.onlinePay(payOrderDto);
        return ResultObject.ok("预支付成功").setData(resPlaceAnOrderDto);
    }
    @ApiOperation(value = "申请开票", notes = "ywb")
    @PostMapping("/applyInvoice")
    public ResultObject<Void> applyInvoice(@RequestBody @Validated ReqApplyInvoiceDto req) {
        orderService.applyInvoice(req);
        return ResultObject.ok("申请成功");
    }
    @ApiOperation(value = "附件上传", notes = "ywb")
    @PostMapping("/uploadAttachments")
    public ResultObject<Void> uploadAttachments(@RequestBody @Validated  ReqUploadAttachmentsDto dto) {
        orderService.uploadAttachments(dto);
        return ResultObject.ok("上传成功");
    }

}
